package day_007;

import java.util.Random;
import java.util.Scanner;

public class demo4 {
    //需求：双色球
    public static void main(String[] args) {
        //1.确定中奖号码
        int arr[]=creatprice();
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
        }

        //2.用户输入中奖号码
        int userarr[]=userprice();
//        for (int i = 0; i < arr.length; i++) {
//            System.out.print(userarr[i]+" ");
//        }
        //3.判断中奖号码
        int redcount=0;
        int bluecount=0;
        //判断红球
        for(int i=0;i<userarr.length-1;i++){
            for(int j=0;j<arr.length-1;j++){
                if(userarr[i]==arr[j]){
                    redcount++;
                    break;
                }
            }
        }
        //判断蓝球
        if(userarr[userarr.length-1]==arr[arr.length-1]){
            bluecount++;
        }
        System.out.println(redcount);
        System.out.println(bluecount);
        //判断是否中奖
        if(redcount==6&&bluecount==1){
            System.out.println("1000万");
        }
        //...

    }

    public static int[] userprice() {
        int arr[]=new int[7];
        Scanner sc=new Scanner(System.in);
        for (int i = 0; i < 6; ) {
            System.out.println("请输入"+(i+1)+"个红球号码");
            int rednum=sc.nextInt();
            if(rednum>=1&&rednum<=33) {
                boolean flag=contains(arr,rednum);
                if(!flag) {
                    arr[i] = rednum;
                    i++;
                }
                else{
                    System.out.println("号码重复");
                }
            }
            else{
                System.out.println("号码不在正确范围");
            }
        }
        System.out.println("请输入蓝球号码");
        int bluenum= sc.nextInt();
        while(true){
            if(bluenum>=1&&bluenum<=16){
                arr[arr.length-1] = bluenum;
                break;
            }
            else{
                System.out.println("请输入正确范围");
            }
        }
        return arr;
    }

    public static int[] creatprice() {
        int arr[]=new int[7];
        Random r=new Random();
        //红球号码
        for (int i = 0; i < 6;) {
            int rednum= r.nextInt(33)+1;
            boolean flag=contains(arr,rednum);
            if(!flag) {
                arr[i] = rednum;
                i++;
            }
        }
        //蓝球号码
        int bluenum= r.nextInt(16)+1;
            arr[arr.length-1] = bluenum;
        return arr;
    }

    public static boolean contains(int[] arr,int num) {
        for (int i=0;i<arr.length;i++) {
            if(arr[i]==num){
                return true;
            }
        }
        return false;
    }




}
